public class P3 {
    public static void main(String[] args) {
        int limit = 20000;
        boolean[] isPrime = new boolean[limit + 1];
        
        for (int i = 2; i <= limit; i++) isPrime[i] = true;
        
        for (int i = 2; i * i <= limit; i++) {
            if (isPrime[i]) {
                for (int j = i * i; j <= limit; j += i) {
                    isPrime[j] = false;
                }
            }
        }
        
        int count = 0;
        for (int i = 2; i <= limit; i++) {
            if (isPrime[i]) {
                System.out.printf("%-6d", i);
                count++;
                if (count % 5 == 0) System.out.println();
            }
        }
        
        System.out.println("\n素数个数: " + count);
    }
}